package br.com.fiap.cincoMob.TrabalhoFinal;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class History {
	private List<ItemHistory> itens;
	
	public History(){
		super();
		itens = new ArrayList<ItemHistory>();
	}
	
	public List<ItemHistory> getItens() {
		return itens;
	}

	public void setItens(List<ItemHistory> itens) {
		this.itens = itens;
	}
	
	public ItemHistory getLastItem(){
		if(itens.size() > 0){
			return itens.get(itens.size() - 1);
		} else {
			return null;
		}
	}
	
	public void print(){
		for (ItemHistory item : itens) {
			System.out.println(item);
		}
	}

	public void writeInFile(int decimalSize){
		try {
			FileWriter fw;
			fw = new FileWriter("saida.txt");
			PrintWriter out = new PrintWriter(fw);
			for (ItemHistory item : itens) {
				item.print(decimalSize, out);
			}
			out.close();			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
